home *** CD-ROM | disk | FTP | other *** search
- /*
- * linerid.c
- *
- * Practical Algorithms for Image Analysis
- *
- * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
- */
-
-
- /* LINERID: program takes input PCC, removes lines below minimum
- * tolerance, and writes output PCC
- * usage: linerid infile outfile [-e MINLINE_EE] [-f MINLINE_FE] [-L]
- *
- */
-
- #define MINLINE_EE 30 /* end to endline minimum length */
- #define MINLINE_FE 10 /* end to/from feature minimum length */
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "pcc2.h" /* for PCC programs */
- extern void print_sos_lic ();
-
- unsigned char *fcCode; /* code storage */
- long nByteCode; /* no. bytes in code storage */
-
- int input (int, char **, long *, long *);
- int usage (short);
-
- int argc;
- char *argv[];
- long *minEE, *minFE;
-
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- long width, height; /* image size */
- struct attributes *attr; /* level 1 attributes */
- long nAttr; /* no. of line structures in attr. array */
- long minEE, minFE; /* minimum EE and FE line thresholds */
-
- /* user input */
- if ((input (argc, argv, &minEE, &minFE)) < 0)
- return (-1);
- minEE *= 10; /* length units = [pixels * 10 ] */
- minFE *= 10;
-
- /* open input PCC file */
- if (pccread (argv[1], &fcCode, &nByteCode, &width, &height) == -1)
- exit (1);
- printf ("image size: %dx%d, PCC length = %d\n", width, height, nByteCode);
-
- /* construct tables of PCC decodes */
- pccdecodes ();
-
- /* construct TLC level 1 array of attributes */
- tlc1attr (&attr, &nAttr);
- printf ("number of line features = %d\n", nAttr);
-
- /* remove PCC code for lines below minimum length tolerance */
- tlc1tag (attr, nAttr, minEE, minFE);
- printf ("number of PCC bytes before filtering = %4d\n", nByteCode);
- nByteCode = tlc1rid (attr, nAttr);
- printf ("number of PCC bytes after filtering = %4d\n", nByteCode);
-
- /* write out PCC file */
- pccwrite (argv[2], fcCode, nByteCode, width, height);
-
- return (0);
- }
-
-
- /* USAGE: function gives instructions on usage of program
- * usage: usage (flag)
- * When flag is 1, the long message is given, 0 gives short.
- */
-
- int
- usage (flag)
- short flag; /* flag =1 for long message; =0 for short message */
- {
-
- /* print short usage message or long */
- printf ("USAGE: linerid infile outfile [-e MINLINE_EE] [-f MINLINE_FE] [-L]\n");
- if (flag == 0)
- return (-1);
-
- printf ("\nlinerid filters out small lines of two types:\n");
- printf (" EE lines are isolated endline-to-endline segments;\n");
- printf (" FE lines are attached feature-to-endline segments.\n\n");
- printf ("ARGUMENTS:\n");
- printf (" infile: input filename (PCC)\n");
- printf (" outfile: output filename (PCC)\n\n");
- printf ("OPTIONS:\n");
- printf (" -e MINLINE_EE: minimum length of end-end, isolated lines;");
- printf (" (default=%d)\n", MINLINE_EE);
- printf (" -f MINLINE_FE: minimum length of feature-end, attached lines;");
- printf (" (default=%d)\n", MINLINE_FE);
- printf (" -L: print Software License for this module\n");
-
-
- return (-1);
- }
-
-
- /* INPUT: function reads input parameters
- * usage: input (argc, argv, &minEE, &minFE)
- */
-
- #define USAGE_EXIT(VALUE) {usage (VALUE); return (-1);}
-
- int
- input (argc, argv, minEE, minFE)
- int argc;
- char *argv[];
- long *minEE, *minFE; /* minimum length of EE and FE line segments */
- {
- long n;
-
- if (argc == 1)
- USAGE_EXIT (1);
- if (argc == 2)
- USAGE_EXIT (0);
-
- *minEE = MINLINE_EE;
- *minFE = MINLINE_FE;
-
- for (n = 3; n < argc; n++) {
- if (strcmp (argv[n], "-e") == 0) {
- if (++n == argc)
- USAGE_EXIT (0);
- *minEE = (long) atol (argv[n]);
- }
- else if (strcmp (argv[n], "-f") == 0) {
- if (++n == argc)
- USAGE_EXIT (0);
- *minFE = atol (argv[n]);
- }
- else if (strcmp (argv[n], "-L") == 0) {
- print_sos_lic ();
- exit (0);
- }
- else
- USAGE_EXIT (0);
- }
-
- return (0);
- }
-